<!DOCTYPE html>
<html>

<head>
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta charset="utf-8">
  <title>小球弹跳动画</title>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    #ball {
      background: red;
      height: 100px;
      width: 100px;
      position: absolute;
      top: 10px;
      left: 20px;
      border-radius: 50px;
    }

    #floor {
      position: absolute;
      bottom: 10px;
      left: 0px;
      width: 350px;
      height: 1px;
      border-top: 5px solid brown;
    }
  </style>
</head>

<body>
  <div id="ball"></div>
  <div id="floor"></div>

  <script type="text/javascript">
    ; (function () {

      var down = false,
        trans = 'transition',
        eventName = 'transitionend';
      if (typeof document.body.style.webkitTransition === 'string') {
        trans = 'webkitTransition';
        eventName = 'webkitTransitionEnd';
      } else if (typeof document.body.style.MozTransition === 'string') {
        trans = 'MozTransition';
      }
      console.log(eventName+down)

      var ball = document.getElementById('ball');
      var floor = document.getElementById('floor');

      function bounce() {
        console.log(down)
        if (down) {
          ball.style[trans] = "Top 1s cubic-bezier(0,.27,.32,1)";
          ball.style.top = '10px';
          down = false;
        } else {
          ball.style[trans] = "Top 1s cubic-bezier(1,0,0.96,0.91)";
          ball.style.top = (floor.offsetTop - 100) + 'px';
          down = true;
        }
      }

      ball.addEventListener(eventName, bounce);
      bounce();

    })();

  </script>
</body>

</html>